STEP 1: The Numbered File approach

The numbered-file approach uses JavaScript to generate a random number in a range determined by the number of files you'd like randomized. For example, if you have 15 music files that you'd like randomized, name the files something1.rmf, something2.rmf, something3.rmf,........something15.rmf. Then place these files in the same folder along with the HTML file that is to play them. The JavaScript will then generate a random number between 1 and 15 and create a filename using this number.

The JavaScript for this approach is shown in the source code listing below. Place it towards the end of your HTML file, in the spot where you'd like the random music file to be embedded. There are three variables you can use to customize the randomisation code: totalFiles, filesPrefix, and filesSuffix. They are highlighted in the copy-and-paste code listing.

Copy-and-Paste
<SCRIPT SRC="music-object.js"></SCRIPT>

<SCRIPT LANGUAGE=JavaScript><!-- //

totalFiles = 15;
filesPrefix = "your-files-prefix";
filesSuffix = "your-files-suffix";

Music.magicEmbed (
   'SRC="' +
   filesPrefix +
   (Math.round (Math.random () * (totalFiles - 1)) + 1) +
   filesSuffix + '" ' +
   'TYPE="audio/rmf" ' +
   'AUTOSTART=TRUE ' +
   'WIDTH=0 ' +
   'HEIGHT=0 ' +
   'VOLUME=100 ' +
   'LOOP=TRUE'
);

// --></SCRIPT>

Notice how we are using the Music.magicEmbed function, which is defined in the "music-object.js" JavaScript file that is sourced into the HTML document. We could have just used a document.writeln statement instead, but Music Object's Music.magicEmbed function performs some automatic compatibility testing to see if the user has the Beatnik Player installed. The Music.magicEmbed function also writes the correct EMBED tag or OBJECT tag syntax into the HTML document, depending on whether the user is browsing with Netscape Navigator or Microsoft Internet Explorer.